[Proposal] Add agentic ID support#1027
Open
Avery-Dunn wants to merge 3 commits intoavdunn/fic-supportfrom
Open
[Proposal] Add agentic ID support#1027Avery-Dunn wants to merge 3 commits intoavdunn/fic-supportfrom
Avery-Dunn wants to merge 3 commits intoavdunn/fic-supportfrom
Conversation
c94ca99 to
07bdbb7
Compare
0d78e28 to
9752d99
Compare
acquireTokenForAgent API for agent identity scenarios
acquireTokenForAgent API for agent identity scenarios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the high-level
acquireTokenForAgentAPI to MSAL Java, enabling the full three-leg agent identity token acquisition flow. This is the developer-facing API that orchestrates the FMI (PR 1) and UserFIC (PR 2) building blocks internally, eliminating the need for developers to manage multiple CCA instances, assertion callbacks, and token caches manually.The API matches the
AcquireTokenForAgentAPI on MSAL .NET'savdunn/agent-identity-apisbranch (PR #5883).What's included
New public APIs:
IConfidentialClientApplication.acquireTokenForAgent(AcquireTokenForAgentParameters)— acquires a user-scoped token for agent scenarios via the three-leg FMI/FIC flowAcquireTokenForAgentParameters— parameter object with builder pattern, supporting:.builder(scopes, agentIdentity)— required: target scopes and agent identity.forceRefresh(boolean)— bypass the user token cache.tenant(String)— override tenant for all inner calls.claims(ClaimsRequest)— claims challenge support, propagated to inner calls.extraHttpHeaders(Map)/.extraQueryParameters(Map)— extensibility, propagated to inner callsAgentIdentity— identifies the agent application and (optionally) the target user:new AgentIdentity(agentApplicationId, userObjectId)— identify user by OID (recommended)AgentIdentity.withUsername(agentApplicationId, username)— identify user by UPNAgentIdentity.appOnly(agentApplicationId)— app-only flow (Legs 1-2 only, no user token)Three-leg orchestration (
AcquireTokenForAgentSupplier):The supplier orchestrates the full flow internally:
forceRefresh=true.AcquireTokenForClientwithfmiPath=agentAppId. Cached in the Blueprint's app token cache.AcquireTokenForClientwithcredentialFmiPath=agentAppId(cache-key-only, not sent in HTTP body). The Agent CCA's assertion callback triggers Leg 1. Cached with extended cache key hash for isolation.AcquireTokenByUserFederatedIdentityCredential. Always fetches from network (cache was already checked in the silent check above). Result is stored in the Agent CCA's user token cache.Internal CCA management:
ConfidentialClientApplication.agentCcaCache— aConcurrentHashMapthat stores internal Agent CCA instances, keyed by"agent_" + agentAppIdCache key isolation (
credential_fmi_path):ClientCredentialParameters.credentialFmiPath(String)— new cache-key-only parameter (does NOT send anything in the HTTP body, unlikefmiPath)extCacheKeyHashcomputed fromcredential_fmi_path=agentAppId, preventing collisions with user tokens that share the same scope (api://AzureADTokenExchange/.default)fmiPathandcredentialFmiPathare mutually exclusive (validated at build time)TokenCache.computeExtCacheKeyHashForRequest()extended to handle bothfmi_pathandcredential_fmi_pathcomponentsAcquireTokenByClientCredentialSupplierpropagatescredentialFmiPathhash to silent lookupsWithFmiPathForClientAssertion(agentAppId)behaviorParameter propagation:
Outer
AcquireTokenForAgentParametersare propagated to all inner token calls:claims→ Legs 1, 2, 3, and silent check (ensures claims challenges cause cache bypass)tenant→ Legs 1, 2, 3, and silent checkextraQueryParameters→ Legs 1, 2, 3, and silent checkextraHttpHeaders→ Legs 1, 2, 3, and silent checkThis matches .NET's
PropagateOuterRequestParameterspattern.Tests:
AgentIdentityTest.java— 15 unit tests covering:hasUserIdentifier()behavior for all three variantsAcquireTokenForAgentTest.java— 18 unit tests covering:TwoUpnstest)fmi_pathin request bodygrant_type=user_ficcredential_fmi_path(verifies exact hash, no HTTP body leak, correct assertion used by subsequent users)AgenticIT.java— 4 integration tests covering the full agent identity flow with real certificatesAlignment with MSAL .NET
This implementation matches the agent identity behavior on MSAL .NET's
avdunn/agent-identity-apisbranch. Key equivalences:AcquireTokenForAgent(scopes, agentIdentity)acquireTokenForAgent(AcquireTokenForAgentParameters.builder(scopes, agentIdentity).build())AgentIdentity(agentAppId, userObjectId)new AgentIdentity(agentAppId, userObjectId)AgentIdentity.WithUsername(agentAppId, username)AgentIdentity.withUsername(agentAppId, username)AgentIdentity.AppOnly(agentAppId)AgentIdentity.appOnly(agentAppId)WithForceRefresh(true).forceRefresh(true)WithFmiPathForClientAssertion(agentAppId)on Leg 2ClientCredentialParameters.credentialFmiPath(agentAppId)on Leg 2PropagateOuterRequestParameterspropagateToClientCredentialParams/propagateToUserFicParams/propagateToSilentParamsAgentCcaCachedictionary on CCAagentCcaCacheConcurrentHashMap on CCAAppTokenCacheInternal/UserTokenCacheInternalextCacheKeyHashisolation (Java's existing architecture)Known differences from .NET
WithCorrelationId()propagated to all inner callscorrelationId; adding it is a cross-cutting API changeextCacheKeyHash+homeAccountIdisolationcredential_fmi_pathhash provides equivalent isolation for Leg 2WithSendX5CWithAttributes(xms_attr claims)